home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-ppclinux.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-07  |  2.7 KB  |  93 lines

  1. /* ieee-utils/fp-ppclinux.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough, John Fisher
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <fpu_control.h>
  22. #include <gsl/gsl_errno.h>
  23. #include <gsl/gsl_ieee_utils.h>
  24.  
  25.  
  26. /*
  27.  * Identical to fp-linux.c, except with references to
  28.  * _FPU_SINGLE, _FPU_DOUBLE, _FPU_EXTENDED, _FPU_MASK_DM
  29.  * and _FPU_MASK_PM converted to errors.
  30.  */
  31.  
  32. int
  33. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  34. {
  35.   unsigned short mode = 0 ;
  36.  
  37.   switch (precision)
  38.     {
  39.     case GSL_IEEE_SINGLE_PRECISION:
  40.       GSL_ERROR ("powerpc linux only supports default precision rounding", GSL_EUNSUP);
  41.       break ;
  42.     case GSL_IEEE_DOUBLE_PRECISION:
  43.       GSL_ERROR ("powerpc linux only supports default precision rounding", GSL_EUNSUP);
  44.       break ;
  45.     case GSL_IEEE_EXTENDED_PRECISION:
  46.       GSL_ERROR ("powerpc linux only supports default precision rounding", GSL_EUNSUP);
  47.       break ;
  48.     }
  49.  
  50.   switch (rounding)
  51.     {
  52.     case GSL_IEEE_ROUND_TO_NEAREST:
  53.       mode |= _FPU_RC_NEAREST ;
  54.       break ;
  55.     case GSL_IEEE_ROUND_DOWN:
  56.       mode |= _FPU_RC_DOWN ;
  57.       break ;
  58.     case GSL_IEEE_ROUND_UP:
  59.       mode |= _FPU_RC_UP ;
  60.       break ;
  61.     case GSL_IEEE_ROUND_TO_ZERO:
  62.       mode |= _FPU_RC_ZERO ;
  63.       break ;
  64.     default:
  65.       mode |= _FPU_RC_NEAREST ;
  66.     }
  67.  
  68.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  69.     mode |= _FPU_MASK_IM ;
  70.  
  71.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  72.     GSL_ERROR ("powerpc linux does not support the denormalized operand exception. "
  73.            "Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  74.  
  75.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  76.     mode |= _FPU_MASK_ZM ;
  77.  
  78.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  79.     mode |= _FPU_MASK_OM ;
  80.  
  81.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  82.     mode |= _FPU_MASK_UM ;
  83.  
  84.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  85.     {
  86.      GSL_ERROR ("powerpc linux does not support traps for inexact operations", GSL_EUNSUP) ;
  87.     }
  88.  
  89.   _FPU_SETCW(mode) ;
  90.  
  91.   return GSL_SUCCESS ;
  92. }
  93.